package com.undefind;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.*;

import static org.junit.jupiter.api.Assertions.*;

class NGuessNumberTest {

    NGuessNumber mainClass;
    @BeforeEach
    void setUp() {
        mainClass = new NGuessNumber();
    }

    @AfterEach
    void tearDown() {
        mainClass = null;
    }
    @Test
    void compareGuessAnswerTest(){
        int[] answer = mainClass.generateAnswer();
        int[] input = answer;
        Map<Integer,Boolean> result = new HashMap<>();
        for (int i = 0;i<answer.length;i++){
                result.put(answer[i],true);
        }
        assertEquals(mainClass.compareGuessAnswer(answer,input),result);
    }
    @Test
    void isWinTest(){
        int[] answer = mainClass.generateAnswer();
        int[] input = answer;
        Map<Integer,Boolean> result = new HashMap<>();
        for (int i = 0;i<answer.length;i++){
            result.put(answer[i],true);
        }
        assertEquals(mainClass.isWin(mainClass.compareGuessAnswer(answer,input)),true);
    }
    @Test
    void getPlayerInputTest(){
    }
    @Test
    void generateAnswerTest() {
        int[] reslut = mainClass.generateAnswer();
        assertEquals(reslut.length,4);
        assertEquals(isRepetition(reslut),false);
    }
    public boolean isRepetition(int[] args) {
        Set<Object> set = new HashSet<>();
        for (int arg : args) set.add(arg);
        return set.size() == args.length;
    }
}